package yt.demo.appcoresystem.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import yt.demo.appcommondb.base.BaseService;
import yt.demo.appcommondb.vo.ConditionVO;
import yt.demo.appcoresystem.dto.RoleDTO;
import yt.demo.appcoresystem.entity.SystemRole;
import yt.demo.appcoresystem.mapper.SystemRoleMapper;
import yt.demo.appcoresystem.service.ISystemRoleMenuService;
import yt.demo.appcoresystem.service.ISystemRoleService;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class SystemRoleService extends BaseService<SystemRole, SystemRoleMapper> implements ISystemRoleService {

    ISystemRoleMenuService roleMenuService;

    @Autowired
    public SystemRoleService(SystemRoleMapper mapper,ISystemRoleMenuService roleMenuService) {
        super(mapper, SystemRole.class);
        this.roleMenuService = roleMenuService;
    }

    @Override
    protected List<ConditionVO<SystemRole, ?>> whereConditions(SystemRole params) {
        List<ConditionVO<SystemRole, ?>> conditions = new ArrayList<>();
        if (params.getName() != null) {
            conditions.add(ConditionVO.createCondition(SystemRole::getName, "like", params.getName()));
        }
        if (params.getCode() != null) {
            conditions.add(ConditionVO.createCondition(SystemRole::getCode, "like", params.getCode()));
        }
        if (params.getStatus() != null) {
            conditions.add(ConditionVO.createCondition(SystemRole::getStatus, "eq", params.getStatus()));
        }
        return conditions;
    }

    public Void syncRoleMenus(RoleDTO.updateMenus req){
        this.roleMenuService.syncRoleMenus(req.getId(),req.getMenu_ids());
        return null;
    }

}
